// EducationHistory.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Facebook.Service
{

	/// <summary>
	/// Represents a Facebook education history entry on the user's profile.
	/// </summary>
	public sealed class EducationHistory : FacebookEntity
	{

		private bool _concentrationsTransformed;

		internal EducationHistory(Hashtable educationHistoryState)
			: base(educationHistoryState)
		{
		}

		/// <summary>
		/// The list of named concentrations.
		/// </summary>
		public ICollection<string> Concentrations
		{
			get
			{
				if (_concentrationsTransformed == false)
				{
					return TransformConcentrations();
				}
				return (ICollection<string>)this["concentrations"];
			}
		}

		/// <summary>
		/// The name of the school.
		/// </summary>
		public string Name
		{
			get
			{
				return GetState<string>("name") ?? String.Empty;
			}
		}

		/// <summary>
		/// The year of graduation.
		/// </summary>
		public string Year
		{
			get
			{
				return GetState<string>("year") ?? String.Empty;
			}
		}

		private ICollection<string> TransformConcentrations()
		{
			Debug.Assert(_concentrationsTransformed == false);

			ArrayList concentrationsState = this["concentrations"] as ArrayList;
			string[] concentrations = (concentrationsState != null) ? concentrationsState.ToArray(typeof(string)) as string[] : new string[0];

			this["concentrations"] = concentrations;
			_concentrationsTransformed = true;

			return concentrations;
		}
	}
}
